/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.rssreader;

import org.json.JSONObject;
import org.webos.java.base.Dialog;
import org.webos.java.base.DialogType;
import org.webos.java.base.NetworkManager;
import org.webos.java.base.RemoteMessage;

/**
 *
 * @author Kostya
 */
@DialogType(jsClass="rssreader.FolderEditor")
public class FolderEditor extends Dialog<RSSReader>{

    boolean newFolder = false;
    int id = 0;
    
    public FolderEditor(RSSReader aRSSReader, boolean aNewFolder, int aID, String aName) {
        super(aRSSReader);
        newFolder = aNewFolder;
        id = aID;
        getData().putOpt("newFolder", newFolder);
        getData().putOpt("name", aName);
        show();
    }


    @RemoteMessage
    public JSONObject okClick(JSONObject aData){
        String name = aData.optString("name", "");
        if("".equals(name))
            return NetworkManager.getErrorObject(1202, "Name can't be empty");
        if(!getApplication().foldersFeeds.saveFolder(newFolder, id, name))
            return NetworkManager.getErrorObject(1203, "Can't save folder to DB");
        closeDialog(null);
        return null;
    }

}
